package gl.vbm

import gl.util.string
import java.nio.ByteBuffer

class VBMMaterial(buffer: ByteBuffer) {
    val name: String // Name of material
    val ambient: VBMVec3f // Ambient color
    val diffuse: VBMVec3f // Diffuse color
    val specular: VBMVec3f // Specular color
    val specularExp: VBMVec3f // Specular exponent
    val shininess: Float // Shininess
    val alpha: Float // Alpha (transparency)
    val transmission: VBMVec3f // Transmissivity
    val ior: Float // Index of refraction (optical density)
    val ambientMap: String // Ambient map (texture)
    val diffuseMap: String // Diffuse map (texture)
    val specularMap: String // Specular map (texture)
    val normalMap: String // Normal map (texture)

    val nameBytes: ByteArray
    val ambientMapBytes: ByteArray
    val diffuseMapBytes: ByteArray
    val specularMapBytes: ByteArray
    val normalMapBytes: ByteArray
    val textures: VBMMaterialTextures

    init {
        buffer[ByteArray(32).also { nameBytes = it }]
        ambient = VBMVec3f(buffer)
        diffuse = VBMVec3f(buffer)
        specular = VBMVec3f(buffer)
        specularExp = VBMVec3f(buffer)
        shininess = buffer.float
        alpha = buffer.float
        transmission = VBMVec3f(buffer)
        ior = buffer.float
        buffer[ByteArray(64).also { ambientMapBytes = it }]
        buffer[ByteArray(64).also { diffuseMapBytes = it }]
        buffer[ByteArray(64).also { specularMapBytes = it }]
        buffer[ByteArray(64).also { normalMapBytes = it }]
        name = nameBytes.string()
        ambientMap = ambientMapBytes.string()
        diffuseMap = diffuseMapBytes.string()
        specularMap = specularMapBytes.string()
        normalMap = normalMapBytes.string()
        textures = VBMMaterialTextures()
    }
}

class VBMMaterialTextures {
    var diffuse: Int = 0
    var specular: Int = 0
    var normal: Int = 0
}